package com.gluck.cases.common.utils.exception;

import com.gluck.cases.common.utils.enums.BizSerErrorEnum;

/**
 * @ClassName BizSerException
 * @Desc 业务异常
 * @Author I am Gluck
 * @Date 2022/4/28 - 4:39 下午
 **/
public class BizSerException extends RuntimeException{

    private static final long serialVersionUID = 3597437161077704487L;

    /**
     * 异常枚举类
     */
    private BizSerErrorEnum gluckStockSerErrorEnum;

    /**
     * 错误码
     */
    private String errCode;

    /**
     * 错误信息
     */
    private String errMsg;

    /**
     * 是否输出栈信息 默认输出
     */
    private boolean needPrintStack = true;

    public BizSerException(BizSerErrorEnum errorEnum, String errMsg) {
        super(errMsg);
        this.gluckStockSerErrorEnum = errorEnum;
        this.errMsg = errMsg;
        this.errCode = errorEnum.getGluckStockErrorCode();
    }

    public BizSerException(BizSerErrorEnum errorEnum){
        super(errorEnum.getErrorMsg());
        this.gluckStockSerErrorEnum = errorEnum;
        this.errMsg = errorEnum.getErrorMsg();
        this.errCode = errorEnum.getGluckStockErrorCode();
    }

    public BizSerException(BizSerErrorEnum errorEnum, boolean needPrintStack){
        super(errorEnum.getErrorMsg());
        this.gluckStockSerErrorEnum = errorEnum;
        this.errMsg = errorEnum.getErrorMsg();
        this.errCode = errorEnum.getGluckStockErrorCode();
        this.needPrintStack = needPrintStack;
    }

    public BizSerException(BizSerErrorEnum errorEnum, Throwable e){
        super(errorEnum.getErrorMsg(), e);
        this.gluckStockSerErrorEnum = errorEnum;
        this.errMsg = errorEnum.getErrorMsg();
        this.errCode = errorEnum.getGluckStockErrorCode();
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public boolean isNeedPrintStack() {
        return needPrintStack;
    }

    public void setNeedPrintStack(boolean needPrintStack) {
        this.needPrintStack = needPrintStack;
    }
}
